package com.ruoyi.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysRetailMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysRetailTaskMapper;
import com.ruoyi.system.domain.SysRetailTask;
import com.ruoyi.system.service.ISysRetailTaskService;

/**
 * 散户生产任务Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-25
 */
@Service
public class SysRetailTaskServiceImpl implements ISysRetailTaskService
{
    @Autowired
    private SysRetailTaskMapper sysRetailTaskMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysRetailMapper sysRetailMapper;
    /**
     * 查询散户生产任务
     *
     * @param rId 散户生产任务主键
     * @return 散户生产任务
     */
    @Override
    public SysRetailTask selectSysRetailTaskByRId(Long rId, Long orderId)
    {
        Map<String, Object> params = new HashMap<>();
        params.put("rId", rId);
        params.put("orderId", orderId);
        return sysRetailTaskMapper.selectSysRetailTaskByRId(params);
    }

    /**
     * 查询散户生产任务列表
     *
     * @param sysRetailTask 散户生产任务
     * @return 散户生产任务
     */
    @Override
    public List<SysRetailTask> selectSysRetailTaskList(SysRetailTask sysRetailTask)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = sysUserMapper.selectUserById(loginUser.getUserId());
        sysRetailTask.setSupplierId(user.getSupplierId());
        return sysRetailTaskMapper.selectSysRetailTaskList(sysRetailTask);
    }

    /**
     * 新增散户生产任务
     *
     * @param sysRetailTask 散户生产任务
     * @return 结果
     */
    @Override
    public int insertSysRetailTask(SysRetailTask sysRetailTask)
    {
        return sysRetailTaskMapper.insertSysRetailTask(sysRetailTask);
    }

    /**
     * 修改散户生产任务
     *
     * @param sysRetailTask 散户生产任务
     * @return 结果
     */
    @Override
    public int updateSysRetailTask(SysRetailTask sysRetailTask)
    {

        return sysRetailTaskMapper.updateSysRetailTask(sysRetailTask);
    }

    /**
     * 批量删除散户生产任务
     *
     * @param rIds 需要删除的散户生产任务主键
     * @return 结果
     */
    @Override
    public int deleteSysRetailTaskByRIds(Long[] rIds)
    {
        return sysRetailTaskMapper.deleteSysRetailTaskByRIds(rIds);
    }

    /**
     * 删除散户生产任务信息
     *
     * @param rId 散户生产任务主键
     * @return 结果
     */
    @Override
    public int deleteSysRetailTaskByRId(Long rId)
    {
        return sysRetailTaskMapper.deleteSysRetailTaskByRId(rId);
    }
}
